#ifndef _CBUF_H
#define _CBUF_H

#include <stdio.h>

#define CBUF_CACHE_SIZEB	64

// typedef unsigned char uint8_t;

typedef struct {
	char *baseAddr;
	uint8_t phyLength;
	uint8_t readCount;
	uint8_t writeCount;
} cbuf_t;

#define CBUF_ALLOC(cname, size) \
static char cname##_base[size]; \
static cbuf_t cname = { \
	.baseAddr = cname##_base, \
	.phyLength = sizeof(cname##_base), \
	.readCount = 0, \
	.writeCount = 0 \
};

void CBufInit(cbuf_t *cbuf, char *buffer, int bufferLen);
int CBufWrite(cbuf_t *cbuf, const char *writeBuffer, int bufferLengthByte);
int CBufRead(cbuf_t *cbuf, char *readBuffer, int bufferLengthByte);
int getDataCount(cbuf_t *cbuf);

#endif
